package com.springboot.testgroovy

import cn.hutool.core.date.DateUtil
import cn.hutool.crypto.digest.MD5
import cn.hutool.http.HttpUtil
import cn.hutool.http.Method
import org.springframework.util.StopWatch

class BondQueryController extends GroovyTestCase {

    def host = "http://localhost:10028"
//    def host = "http://localhost:10088"
    def auth = 'Authorization'
    def dev = 'dev'

    void 'test 1'() {
        println DateUtil.betweenDay(DateUtil.parseDate('2023-05-10'), DateUtil.parseDate('2023-05-09'), true)
    }

    void 'test 询价-新增-筛选'() {
        StopWatch sw = new StopWatch("数据查询请求");
        sw.start()
        def url = "${host}/bondQuery/listBondByInquiryBuy"
//        def param = '{"securityCode":["142038.SH"],"remainingPeriods":"diy|2y|3y"}'
        def param = '{\n' +
                '    "publisherCode": [\n' +
                '        "10000001",\n' +
                '        "10000002"\n' +
                '    ]\n' +
                '}'

        def response = HttpUtil.createRequest(Method.POST, url)
                .body(param)
                .header(auth, dev)
                .execute()
                .body()
        sw.stop()
        StopWatch sw1 = new StopWatch("打印返回");
        sw1.start()
        println response
        sw1.stop()

        println sw.prettyPrint()
        println sw1.prettyPrint()
    }

    void testInquirySort() {
        def url = "${host}/xhInquiryTradeMainInstruction/pageList"
        def param = '{\n' +
                '    "reqPageNum": 1,\n' +
                '    "reqPageSize": 50,\n' +
                '    "instBeginDate": "2023-05-13",\n' +
                '    "instEndDate": "2023-05-13"\n' +
                '}'

        def response = HttpUtil.createRequest(Method.POST, url)
                .body(param)
                .header(auth, dev)
                .execute()
                .body()
        println "response = $response"
    }

    void testEamilSend() {

    }

    void "test_快速改价保存"() {
        def url = "${host}/offipoInquiryInstruction/batchUpdateByFast"
        def param = '[\n' +
                '    {\n' +
                '        "businessType": "WXXGSG",\n' +
                '        "buttonCode": "WXXGSG_KSGJ_BC",\n' +
                '        "inquiryInstructions": [\n' +
                '            {\n' +
                '                "highlightFlag": null,\n' +
                '                "enqEndDate": null,\n' +
                '                "auditUserId": null,\n' +
                '                "outInstructionNo": null,\n' +
                '                "instructionsStatusName": "已改价待上报",\n' +
                '                "createUserId": "admin",\n' +
                '                "prodName": "新华人寿保险股份有限公司-分红-团体分红",\n' +
                '                "inquiryPrice": 11,\n' +
                '                "shTrusteeshipSeat": null,\n' +
                '                "prodCode": "I001100002",\n' +
                '                "szSecAccountNo": null,\n' +
                '                "maxInquiryPrice": null,\n' +
                '                "inquiryAuditStatus": "-",\n' +
                '                "shortlistedTime": null,\n' +
                '                "shortListedDate": null,\n' +
                '                "dataStatusName": null,\n' +
                '                "freezeHappenMoney": null,\n' +
                '                "auditTime": null,\n' +
                '                "validFlag": "0",\n' +
                '                "marketCode": "XSHE",\n' +
                '                "interCode": "301399.SZ",\n' +
                '                "createTime": "2023-05-09 11:56:43",\n' +
                '                "assetType": null,\n' +
                '                "securityName": "英特科技",\n' +
                '                "instructionCheckDetail": null,\n' +
                '                "inquiryDataSource": "1",\n' +
                '                "ipoReportCheck": null,\n' +
                '                "securityCode": "301399",\n' +
                '                "auditStatus": null,\n' +
                '                "updateUserId": null,\n' +
                '                "shortListedCheck": null,\n' +
                '                "inquiryQty": 7300000,\n' +
                '                "enqBeginDate": null,\n' +
                '                "quotaCheck": "1",\n' +
                '                "shortListedPrice": null,\n' +
                '                "auditUserName": null,\n' +
                '                "inquiryAuditStatusName": null,\n' +
                '                "shortListedAmount": null,\n' +
                '                "prodType": "ASS_BXGSWTZH",\n' +
                '                "outInstructionIndex": null,\n' +
                '                "szTrusteeshipSeat": null,\n' +
                '                "createUserName": "系统管理员",\n' +
                '                "shSecAccountNo": null,\n' +
                '                "inquiryCode": "XJZL202305090198",\n' +
                '                "minInquiryPrice": null,\n' +
                '                "inquiryDate": "2023-05-09",\n' +
                '                "dataFlag": "2",\n' +
                '                "ipoUploadTime": null,\n' +
                '                "instructionCheckDetailName": null,\n' +
                '                "updateTime": null,\n' +
                '                "instructionsStatus": "CW10401805",\n' +
                '                "ipoReportCheckName": null,\n' +
                '                "deleteFlag": 0,\n' +
                '                "shortListedCheckName": null,\n' +
                '                "quotaCheckName": "通过",\n' +
                '                "id": "1655783834765103104",\n' +
                '                "currentNode": "N00500",\n' +
                '                "dataStatus": null,\n' +
                '                "prodTypeName": null,\n' +
                '                "roundQtyD": 7300000,\n' +
                '                "baseSchemaName": null,\n' +
                '                "initQtyC": 7300000,\n' +
                '                "shortListedQty": null,\n' +
                '                "shortListedDataSource": null,\n' +
                '                "updateUserName": null,\n' +
                '                "inquiryAmount": 80300000\n' +
                '            },\n' +
                '            {\n' +
                '                "highlightFlag": null,\n' +
                '                "enqEndDate": null,\n' +
                '                "auditUserId": null,\n' +
                '                "outInstructionNo": null,\n' +
                '                "instructionsStatusName": "已改价待上报",\n' +
                '                "createUserId": "admin",\n' +
                '                "prodName": "传统产品",\n' +
                '                "inquiryPrice": 11,\n' +
                '                "shTrusteeshipSeat": null,\n' +
                '                "prodCode": "1",\n' +
                '                "szSecAccountNo": null,\n' +
                '                "maxInquiryPrice": null,\n' +
                '                "inquiryAuditStatus": "-",\n' +
                '                "shortlistedTime": null,\n' +
                '                "shortListedDate": null,\n' +
                '                "dataStatusName": null,\n' +
                '                "freezeHappenMoney": null,\n' +
                '                "auditTime": null,\n' +
                '                "validFlag": "0",\n' +
                '                "marketCode": "XSHE",\n' +
                '                "interCode": "301399.SZ",\n' +
                '                "createTime": "2023-05-09 11:56:43",\n' +
                '                "assetType": null,\n' +
                '                "securityName": "英特科技",\n' +
                '                "instructionCheckDetail": null,\n' +
                '                "inquiryDataSource": "1",\n' +
                '                "ipoReportCheck": null,\n' +
                '                "securityCode": "301399",\n' +
                '                "auditStatus": null,\n' +
                '                "updateUserId": null,\n' +
                '                "shortListedCheck": null,\n' +
                '                "inquiryQty": 7300000,\n' +
                '                "enqBeginDate": null,\n' +
                '                "quotaCheck": "1",\n' +
                '                "shortListedPrice": null,\n' +
                '                "auditUserName": null,\n' +
                '                "inquiryAuditStatusName": null,\n' +
                '                "shortListedAmount": null,\n' +
                '                "prodType": "ASS_ZCGLJH",\n' +
                '                "outInstructionIndex": null,\n' +
                '                "szTrusteeshipSeat": null,\n' +
                '                "createUserName": "系统管理员",\n' +
                '                "shSecAccountNo": null,\n' +
                '                "inquiryCode": "XJZL202305090199",\n' +
                '                "minInquiryPrice": null,\n' +
                '                "inquiryDate": "2023-05-09",\n' +
                '                "dataFlag": "2",\n' +
                '                "ipoUploadTime": null,\n' +
                '                "instructionCheckDetailName": null,\n' +
                '                "updateTime": null,\n' +
                '                "instructionsStatus": "CW10401805",\n' +
                '                "ipoReportCheckName": null,\n' +
                '                "deleteFlag": 0,\n' +
                '                "shortListedCheckName": null,\n' +
                '                "quotaCheckName": "通过",\n' +
                '                "id": "1655783834802851840",\n' +
                '                "currentNode": "N00500",\n' +
                '                "dataStatus": null,\n' +
                '                "prodTypeName": null,\n' +
                '                "roundQtyD": 7300000,\n' +
                '                "baseSchemaName": null,\n' +
                '                "initQtyC": 7300000,\n' +
                '                "shortListedQty": null,\n' +
                '                "shortListedDataSource": null,\n' +
                '                "updateUserName": null,\n' +
                '                "inquiryAmount": 80300000\n' +
                '            },\n' +
                '            {\n' +
                '                "highlightFlag": null,\n' +
                '                "enqEndDate": null,\n' +
                '                "auditUserId": null,\n' +
                '                "outInstructionNo": null,\n' +
                '                "instructionsStatusName": "已改价待上报",\n' +
                '                "createUserId": "admin",\n' +
                '                "prodName": "新华人寿保险股份有限公司-分红-个人分红",\n' +
                '                "inquiryPrice": 11,\n' +
                '                "shTrusteeshipSeat": null,\n' +
                '                "prodCode": "I001100003",\n' +
                '                "szSecAccountNo": null,\n' +
                '                "maxInquiryPrice": null,\n' +
                '                "inquiryAuditStatus": "-",\n' +
                '                "shortlistedTime": null,\n' +
                '                "shortListedDate": null,\n' +
                '                "dataStatusName": null,\n' +
                '                "freezeHappenMoney": null,\n' +
                '                "auditTime": null,\n' +
                '                "validFlag": "0",\n' +
                '                "marketCode": "XSHE",\n' +
                '                "interCode": "301399.SZ",\n' +
                '                "createTime": "2023-05-09 11:56:43",\n' +
                '                "assetType": null,\n' +
                '                "securityName": "英特科技",\n' +
                '                "instructionCheckDetail": null,\n' +
                '                "inquiryDataSource": "1",\n' +
                '                "ipoReportCheck": null,\n' +
                '                "securityCode": "301399",\n' +
                '                "auditStatus": null,\n' +
                '                "updateUserId": null,\n' +
                '                "shortListedCheck": null,\n' +
                '                "inquiryQty": 7300000,\n' +
                '                "enqBeginDate": null,\n' +
                '                "quotaCheck": "1",\n' +
                '                "shortListedPrice": null,\n' +
                '                "auditUserName": null,\n' +
                '                "inquiryAuditStatusName": null,\n' +
                '                "shortListedAmount": null,\n' +
                '                "prodType": "ASS_BXGSWTZH",\n' +
                '                "outInstructionIndex": null,\n' +
                '                "szTrusteeshipSeat": null,\n' +
                '                "createUserName": "系统管理员",\n' +
                '                "shSecAccountNo": null,\n' +
                '                "inquiryCode": "XJZL202305090200",\n' +
                '                "minInquiryPrice": null,\n' +
                '                "inquiryDate": "2023-05-09",\n' +
                '                "dataFlag": "2",\n' +
                '                "ipoUploadTime": null,\n' +
                '                "instructionCheckDetailName": null,\n' +
                '                "updateTime": null,\n' +
                '                "instructionsStatus": "CW10401805",\n' +
                '                "ipoReportCheckName": null,\n' +
                '                "deleteFlag": 0,\n' +
                '                "shortListedCheckName": null,\n' +
                '                "quotaCheckName": "通过",\n' +
                '                "id": "1655783834836406272",\n' +
                '                "currentNode": "N00500",\n' +
                '                "dataStatus": null,\n' +
                '                "prodTypeName": null,\n' +
                '                "roundQtyD": 7300000,\n' +
                '                "baseSchemaName": null,\n' +
                '                "initQtyC": 7300000,\n' +
                '                "shortListedQty": null,\n' +
                '                "shortListedDataSource": null,\n' +
                '                "updateUserName": null,\n' +
                '                "inquiryAmount": 80300000\n' +
                '            }\n' +
                '        ],\n' +
                '        "securityFixPrice": {\n' +
                '            "auditUserId": null,\n' +
                '            "createUserId": null,\n' +
                '            "manualPrice": 11,\n' +
                '            "innerCode": null,\n' +
                '            "fixStatusDicExp": null,\n' +
                '            "offPurMax": 7300000,\n' +
                '            "board": "3",\n' +
                '            "maxInquiryPrice": null,\n' +
                '            "fixStatus": null,\n' +
                '            "marketName": "深圳证券交易所",\n' +
                '            "interName": "英特科技",\n' +
                '            "price1": null,\n' +
                '            "auditTime": null,\n' +
                '            "price2": null,\n' +
                '            "marketCode": "XSHE",\n' +
                '            "interCode": "301399.SZ",\n' +
                '            "createTime": null,\n' +
                '            "price3": null,\n' +
                '            "securityName": null,\n' +
                '            "fastPrice": 11,\n' +
                '            "auditStatus": null,\n' +
                '            "updateUserId": null,\n' +
                '            "tempManualPrice": 11,\n' +
                '            "auditUserName": null,\n' +
                '            "stockId": null,\n' +
                '            "enquiryDate": "2023-05-08",\n' +
                '            "createUserName": null,\n' +
                '            "offPurMin": 1000000,\n' +
                '            "minInquiryPrice": null,\n' +
                '            "updateTime": null,\n' +
                '            "unenquiryDate": "2023-05-09",\n' +
                '            "id": null,\n' +
                '            "updateUserName": null,\n' +
                '            "minPurUnit": 100000\n' +
                '        }\n' +
                '    }\n' +
                ']'

        def response = HttpUtil.createRequest(Method.POST, url)
                .body(param)
                .header(auth, dev)
                .execute()
                .body()

        println response
    }

    void "test_owner"() {
        println("----------this+owner-----------")
        def xx = {
            println("xx的：" + this)
            println("xx的：" + owner)

            def aa = {
                println("aa的：" + this)
                println("aa的：" + owner)
            }
            aa.call()
        }
        xx.call()
    }

    void test111() {
        // 在Groovy中，可以使用metaClass类来对元数据添加属性和方法
        // 如String类，添加一个uppers方法
        def aa = "wdwd"
        String.metaClass.toUpper = {
            -> toUpperCase();
        }
        def upper = aa.toUpper()
        println(upper)
        String.metaClass.to = {
            -> toString()
        }
        def to = "2".to()
        println(to)
    }

    void test_inject() {
        def list = ["love", "hello"]
        /**
         * "$elem $sum"可以理解为字符串的拼接，$sum作为起始值还是作为做后的值只需看他在$elem的前面还是后面
         *      如果$sum在后面说明每一次拼接新的元素都在最前面
         *      如果$sum在前面说明每一次拼接新的元素都在最后面
         * */
        def aa = list.inject("ini") {
            sum, elem -> "$elem $sum"
        }
        println(aa)
    }

    void test_expando() {
        // 他的作用类似于GroovyBean类，但是比他更灵活，同时他还类似于Map类，但也比Map更加灵活
        def expando = new Expando();
        expando.name = { -> "abc" }
        expando.say = {
            String s -> "${expando.name} say ${s}"
        }

        def say = expando.say("hello")
        println(say)

        def person = new Expando();

        person.name = "zhangsan"
        person.age = 18

        person.des = {
            println("""-----------description-----------""")
        }
        person.des()
    }

    void testListener() {
        def list = new ObservableList()
        def printer = {
            e -> println(e.class)
        }
        list.addPropertyChangeListener(printer)
        list.add('hello world1')
        list.add('hello world2')
        list.add('hello world3')
        list.remove(0)

    }


}
